package com.ruoyi.web.controller.estate;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.estate.FeeItem;
import com.ruoyi.system.service.estate.IFeeItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收费项目Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/estate/fee/item")
public class FeeItemController extends BaseController
{
    @Autowired
    private IFeeItemService feeItemService;

    /**
     * 查询收费项目列表
     */
    @PreAuthorize("@ss.hasPermi('estate:fee:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(FeeItem feeItem)
    {
        startPage();
        List<FeeItem> list = feeItemService.selectFeeItemList(feeItem);
        return getDataTable(list);
    }

    /**
     * 导出收费项目列表
     */
    @PreAuthorize("@ss.hasPermi('estate:fee:item:export')")
    @Log(title = "收费项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(FeeItem feeItem)
    {
        List<FeeItem> list = feeItemService.selectFeeItemList(feeItem);
        ExcelUtil<FeeItem> util = new ExcelUtil<FeeItem>(FeeItem.class);
        return util.exportExcel(list, "收费项目数据");
    }

    /**
     * 获取收费项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('estate:fee:item:query')")
    @GetMapping(value = "/{itemId}")
    public AjaxResult getInfo(@PathVariable("itemId") Long itemId)
    {
        return success(feeItemService.selectFeeItemById(itemId));
    }

    /**
     * 新增收费项目
     */
    @PreAuthorize("@ss.hasPermi('estate:fee:item:add')")
    @Log(title = "收费项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FeeItem feeItem)
    {
        return toAjax(feeItemService.insertFeeItem(feeItem));
    }

    /**
     * 修改收费项目
     */
    @PreAuthorize("@ss.hasPermi('estate:fee:item:edit')")
    @Log(title = "收费项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FeeItem feeItem)
    {
        return toAjax(feeItemService.updateFeeItem(feeItem));
    }

    /**
     * 删除收费项目
     */
    @PreAuthorize("@ss.hasPermi('estate:fee:item:remove')")
    @Log(title = "收费项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{itemIds}")
    public AjaxResult remove(@PathVariable Long[] itemIds)
    {
        return toAjax(feeItemService.deleteFeeItemByIds(itemIds));
    }
} 